package com.zhengdongzulin.zuke.app.main.findhouse

import android.content.Intent
import android.text.Editable
import android.text.TextWatcher
import android.view.Gravity
import android.view.View
import android.view.ViewGroup
import android.view.animation.Animation
import android.widget.EditText
import android.widget.TextView
import androidx.lifecycle.Observer
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.google.gson.Gson
import com.lxj.androidktx.core.*
import com.lxj.androidktx.livedata.StateLiveData
import com.xuexiang.xui.widget.flowlayout.DefaultFlowTagAdapter
import com.xuexiang.xui.widget.flowlayout.FlowTagLayout
import com.zhengdongzulin.zuke.R
import com.zhengdongzulin.zuke.app.data.City
import com.zhengdongzulin.zuke.app.data.FindHouse
import com.zhengdongzulin.zuke.app.data.FindHousePostData
import com.zhengdongzulin.zuke.base.*
import com.zhengdongzulin.zuke.databinding.ZkFragmentFindHouseBinding
import com.zhengdongzulin.zuke.ext.*
import razerdp.basepopup.BasePopupWindow
import razerdp.util.animation.AnimationHelper
import razerdp.util.animation.TranslationConfig

/**
 * @类名称: CLASS
 * @类描述:
 * @创建人：Jeff
 * @创建时间：2021/6/9 20:53
 * @备注：
 */
class ZKFindHouseActivity : BaseActivity<FindHouseVm, ZkFragmentFindHouseBinding>() {

    var mData: MutableList<FindHouse> = mutableListOf()
    lateinit var mAdapter: VListAdpater

    var mData1: MutableList<Sel> = mutableListOf()
    var mData2: MutableList<Sel> = mutableListOf()
    var mData3: MutableList<Sel> = mutableListOf()
    var mData1sel = Sel()
    var mData2sel = Sel()
    var mData3sel = Sel()

    var mHouseType1 = mutableListOf("不限", "一居", "两居", "三居", "三居+")
    var mHouseType2 = mutableListOf("不限", "两居", "三居", "四居", "四居+")
    var mPrice = mutableListOf("不限", "500元以下", "500-1000元", "1000-2000元", "2000-3000元", "3000元以上")
    var mHouseTypeSel = Sel()
    var mDirectionSel = Sel()
    var mPriceSel = Sel()
    var mdirectionData = mutableListOf<Sel>()

    override fun getLayoutResId(): Int = R.layout.zk_fragment_find_house
    lateinit var mLocationPop: BasePopupWindow
    lateinit var mHouseTypePop: BasePopupWindow
    lateinit var mPricePop: BasePopupWindow
    lateinit var mDirectionPop: BasePopupWindow

    override fun initVM(): FindHouseVm = getVM(FindHouseVm::class.java)

    override fun initView() {
        setTitleContent("找房")
        initHouseTypePopwinndow()
        initPricePopwindow()
    }

    override fun initData() {
        mViewModel.dic_list()
        var city = sp().getString("current_city", "")
        if (mShareViewModel.city.value != null) {
            mViewModel.position_list(mShareViewModel.city.value?.cityId)
            mViewModel.looking(mShareViewModel.city.value?.cityId!!)
            mView.location.setText(mShareViewModel.city.value?.cityName)
        } else if (!city.isNullOrEmpty()) {
            var mCity = city.toBean<City>()
            mViewModel.position_list(mCity.cityId)
            mViewModel.looking(mCity.cityId)
            mView.location.setText(mCity.cityName)
        } else {
            mViewModel.get_city_com_list()
        }


        mAdapter = VListAdpater(mData)
        mAdapter.setOnItemClickListener { adapter, view, position ->
            Intent().put("id", mData[position].houseId)
                .start(this, ZKRoomDetailsActivity::class.java)
        }
        mView.recyclerView.vertical().adapter = mAdapter
        mView.contentView.setEnableRefresh(false)
        mView.contentView.setOnLoadMoreListener {
            mViewModel.mCurrentPage++
            if (mViewModel.mCurrentPage > mViewModel.mPageTotal) {
                mView.contentView.finishLoadMoreWithNoMoreData()
                toast("没有更多数据了")
            } else {
                mViewModel.looking(mShareViewModel.city.value!!.cityId)
            }
        }
    }

    fun resetFilter() {
        mView.sel1.setDrawRight(R.mipmap.up_triangle_down)
        mView.sel1.setColor(R.color.black_66)
        mView.sel3.setDrawRight(R.mipmap.up_triangle_down)
        mView.sel3.setColor(R.color.black_66)
        mView.sel4.setDrawRight(R.mipmap.up_triangle_down)
        mView.sel4.setColor(R.color.black_66)
        mView.recyclerView.scrollToPosition(0)
    }

    fun getData(lat2: String = "", lng2: String = "") {
        mView.contentView.resetNoMoreData()
        mView.statusView.showLoading()
        var post = FindHousePostData().apply {
            when (mData1sel.name) {
                "区域" -> {
                    if (!mData3sel.name.isNullOrEmpty()) {
                        districtId = mData3sel.id
                    } else {
                        townId = mData2sel.id
                    }
                }
                "地铁" -> {
                    stationId = mData3sel.id
                }
                "附近" -> {
                    nearStatus = "1"
                    nearM = mData2sel.id
                    if (mShareViewModel.mLatLng.value != null) {
                        lat = mShareViewModel.mLatLng.value!!.latitude.toString()
                        lng = mShareViewModel.mLatLng.value!!.longitude.toString()
                    }
                }
                "不限" -> {
                }
            }
            if (!mHouseTypeSel.name.isNullOrEmpty()) {
                houseType = mHouseTypeSel.houseType
                if (mHouseTypeSel.minPrice != 0)
                    roomCount = mHouseTypeSel.minPrice.toString()
            }
            if (!mPriceSel.name.isNullOrEmpty() && mPriceSel.name != "不限") {
                minPrice = mPriceSel.minPrice.toString()
                if (mPriceSel.maxPrice != 0)
                    maxPrice = mPriceSel.maxPrice.toString()
            }
            if (!mDirectionSel.name.isNullOrEmpty()) {
                orientationId = mDirectionSel.id
            }
            if (!lat2.isNullOrEmpty()) {
                lat = lat2
                lng = lng2
            }
        }
        var json = Gson().toJson(post)
        val map: Map<String, Any> = HashMap()
        var data: Map<String, Any> = Gson().fromJson(json, map.javaClass)
        mViewModel.mCurrentPage = 1
        mViewModel.looking(mShareViewModel.city.value?.cityId!!, data)
    }

    override fun initListener() {
        mView.search.setOnClickListener {
            dismissPop()
            startActivityForResult(
                Intent().setClass(
                    this,
                    ZKFindHouseSearchPoiActivity::class.java
                ), 0
            )
        }
    }

    override fun onResume() {
        super.onResume()
        if (mShareViewModel.apartmentTypeIsChangeForFindHouse.value != null && mShareViewModel.apartmentTypeIsChangeForFindHouse.value!!) {
            mView.statusView.showLoading()
            mView.location.setText(mShareViewModel.city.value?.cityName)
            getData()
            mShareViewModel.apartmentTypeIsChangeForFindHouse.value = false
        }
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (resultCode == RESULT_OK) {
            data.let {
                var lat = it!!.getDoubleExtra("lat", 0.0)
                var lng = it!!.getDoubleExtra("lng", 0.0)
                initLocationPopwinndow()
                getData(lat.toString(), lng.toString())
                mView.sel1.setDrawRight(R.mipmap.icon_find_house_sel_right_down)
                mView.sel1.setColor(R.color.black_66)
            }
        }
    }

    override fun startObserve() {
        mViewModel.get_city_com_list.observe(this, Observer {
            mViewModel.position_list(it[0].cityId)
            mViewModel.looking(it[0].cityId)
            mView.location.setText(it[0].cityName)
        })
        mViewModel.position_list.observe(this, Observer {
            initLocationPopwinndow(it)
        })
        mViewModel.position_list.state.observe(this, getObserver(mViewModel.position_list))
        mViewModel.dic_list.observe(this, Observer {
            mdirectionData = it
            initHdirectionPopwindow()
        })
        mViewModel.dic_list.state.observe(this, getObserver(mViewModel.dic_list))
        mViewModel.looking.observe(this, Observer {
            mViewModel.mPageTotal = it.pages
            if (mViewModel.mCurrentPage == 1) {
                mData.clear()
            }
            mData.addAll(it.records)
            if (mData.size == 0) {
                mView.statusView.showEmpty()
            } else {
                mView.statusView.showContent()
            }
            mAdapter.notifyDataSetChanged()
            mView.contentView.finishLoadMore()
        })
        mViewModel.looking.state.observe(this, Observer {
            when (it) {
                StateLiveData.State.Empty -> {
                    mView.statusView.showEmpty()
                }
                StateLiveData.State.Error -> {
                    toast(mViewModel.looking.errMsg)
                    mView.statusView.showEmpty()
                }
            }
        })
    }

    fun initLocationPopwinndow(datas: MutableList<Sel>? = null) {
        if (datas != null)
            mData1.addAll(datas)
        mData2.clear()
        mData3.clear()
        for (sel in mData1) {
            sel.isSelect = false
        }
        mData1[mData1.size - 1].isSelect = true
        mData1sel = mData1[mData1.size - 1]
        var viewGroup = layoutInflater.inflate(R.layout.popwindow_find_house_sel1, null)
        var rv1 = viewGroup.findViewById<RecyclerView>(R.id.rv1)
        var rv2 = viewGroup.findViewById<RecyclerView>(R.id.rv2)
        var rv3 = viewGroup.findViewById<RecyclerView>(R.id.rv3)
//        viewGroup.findViewById<View>(R.id.cancel).setOnClickListener {
//            if (mLocationPop.isShowing) mLocationPop.dismiss()
//        }
        val selAdpater1 = SelAdpater(mData1)
        rv1.vertical().adapter = selAdpater1
        val selAdpater2 = SelAdpater(mData2)
        rv2.vertical().adapter = selAdpater2
        val selAdpater3 = SelAdpater(mData3)
        rv3.vertical().adapter = selAdpater3
        selAdpater1.setOnItemClickListener { adapter, view, position ->
            for (i in mData1) {
                i.isSelect = false
            }
            val sel = mData1[position]
            sel.isSelect = true
            mData1sel = sel
            selAdpater1.notifyDataSetChanged()
            mData2.clear()
            mData3.clear()
            mData2sel = Sel()
            mData3sel = Sel()
            if (sel.list != null && sel.list!!.size > 0) {
                for (j in sel.list!!) {
                    j.isSelect = false
                }
                val sel1 = sel.list!![0]
                sel1.isSelect = true
                mData2sel = sel1
                mData2.addAll(sel.list!!)
                rv2.smoothScrollToPosition(0)
                if (sel1.list != null && sel1.list!!.size > 0) {
                    for (j in sel1.list!!) {
                        j.isSelect = false
                    }
                    val sel2 = sel1.list!![0]
                    sel2.isSelect = true
                    mData3sel = sel2
                    mData3.addAll(sel1.list!!)
                    rv3.smoothScrollToPosition(0)
                }
            }
            selAdpater2.notifyDataSetChanged()
            selAdpater3.notifyDataSetChanged()
        }
        selAdpater2.setOnItemClickListener { adapter, view, position ->
            for (i in mData2) {
                i.isSelect = false
            }
            val sel = mData2[position]
            sel.isSelect = true
            mData2sel = sel
            selAdpater2.notifyDataSetChanged()
            mData3.clear()
            mData3sel = Sel()
            if (sel.list != null && sel.list!!.size > 0) {
                for (j in sel.list!!) {
                    j.isSelect = false
                }
                val sel1 = sel.list!![0]
                sel1.isSelect = true
                mData3sel = sel1
                mData3.addAll(sel.list!!)
                rv3.smoothScrollToPosition(0)
            }
            selAdpater3.notifyDataSetChanged()
        }
        selAdpater3.setOnItemClickListener { adapter, view, position ->
            for (i in mData3) {
                i.isSelect = false
            }
            val sel = mData3[position]
            sel.isSelect = true
            mData3sel = sel
            selAdpater3.notifyDataSetChanged()
        }
        mLocationPop = object : BasePopupWindow(this) {
            override fun onCreateShowAnimation(): Animation {
                return AnimationHelper.asAnimation()
                    .withTranslation(TranslationConfig.FROM_TOP)
                    .toShow()
            }

            override fun onCreateDismissAnimation(): Animation {
                return AnimationHelper.asAnimation()
                    .withTranslation(TranslationConfig.TO_TOP)
                    .toDismiss()
            }
        }.apply {
            contentView = viewGroup
            setPopupGravity(Gravity.BOTTOM)
            setHeight(ViewGroup.LayoutParams.WRAP_CONTENT)
            setWidth(ViewGroup.LayoutParams.MATCH_PARENT)
            setAlignBackground(true)
        }
        mLocationPop.setOnDismissListener(object : BasePopupWindow.OnDismissListener() {
            override fun onDismiss() {
                if (!mData1sel.name.isNullOrEmpty() && mData1sel.name != "不限") {
                    mView.sel1.setDrawRight(R.mipmap.up_triangle_sel_down)
                    mView.sel1.setColor(R.color.color_1273f7)
                } else {
                    mView.sel1.setDrawRight(R.mipmap.up_triangle_down)
                    mView.sel1.setColor(R.color.black_66)
                }
                getData()
                mView.statusView.showLoading()
            }

        })
        mView.sel1.setOnClickListener {
            mView.sel1.setDrawRight(R.mipmap.up_triangle_sel)
            mView.sel1.setColor(R.color.color_1273f7)
            dismissPop()
            mLocationPop.showPopupWindow(it)
        }
    }

    fun initHouseTypePopwinndow(type: String = "") {
        var viewGroup = layoutInflater.inflate(R.layout.popwindow_find_house_sel2, null)
        var housetypeData1 = mutableListOf<Sel>()
        var housetypeData2 = mutableListOf<Sel>()
        for (s in mHouseType1.indices) {
            if (s == 0 && type == "整租") {
                housetypeData1.add(Sel(mHouseType1[s], null, true, s, 0, "1"))
                mView.sel2.setDrawRight(R.mipmap.up_triangle_sel)
                mView.sel2.setColor(R.color.color_1273f7)
                mHouseTypeSel = housetypeData1[0]
            } else {
                housetypeData1.add(Sel(mHouseType1[s], null, false, s, 0, "1"))
            }
        }
        for (s in mHouseType2.indices) {
            if (s == 0 && type == "合租") {
                mView.sel2.setDrawRight(R.mipmap.up_triangle_sel)
                mView.sel2.setColor(R.color.color_1273f7)
                housetypeData2.add(
                    Sel(
                        mHouseType2[s],
                        null,
                        true,
                        (if (s != 0) s + 1 else s),
                        0,
                        "2"
                    )
                )
                mHouseTypeSel = housetypeData2[0]
            } else {
                housetypeData2.add(
                    Sel(
                        mHouseType2[s],
                        null,
                        false,
                        (if (s != 0) s + 1 else s),
                        0,
                        "2"
                    )
                )
            }
        }
        var rv1 = viewGroup.findViewById<RecyclerView>(R.id.rv1)
        var rv2 = viewGroup.findViewById<RecyclerView>(R.id.rv2)
        var tv_empty1 = viewGroup.findViewById<TextView>(R.id.tv_empty1)
        viewGroup.findViewById<View>(R.id.reset).setOnClickListener {
            for (s in housetypeData1) {
                s.isSelect = false
            }
            for (s in housetypeData2) {
                s.isSelect = false
            }
            mHouseTypeSel = Sel()
            rv1.updateData(housetypeData1)
            rv2.updateData(housetypeData2)
        }
//        viewGroup.findViewById<View>(R.id.cancel).setOnClickListener {
//            mHouseTypePop.dismiss()
//        }
        viewGroup.findViewById<View>(R.id.ok).setOnClickListener {
            mHouseTypePop.dismiss()
        }
        rv1.vertical(5).bindData(
            housetypeData1,
            R.layout.item_popwidow_findhouse_sel_house_type
        ) { holder, item, position ->
            val view = holder.getView<TextView>(R.id.name)
            view.text = item.name
            if (item.isSelect) {
                view.setBackgroundResource(R.drawable.item_popwindow_findhouse_sel_house_type_sel)
                view.setTextColor(color(R.color.white))
            } else {
                view.setBackgroundResource(R.drawable.item_popwindow_findhouse_sel_house_type)
                view.setTextColor(color(R.color.gray_99))
            }
        }.itemClick { data: List<Sel>, holder, position ->
            for (s in housetypeData1) {
                s.isSelect = false
            }
            for (s in housetypeData2) {
                s.isSelect = false
            }
            mHouseTypeSel = data[position]
            data[position].isSelect = true
            rv1.updateData(data)
            rv2.updateData(housetypeData2)
        }
        rv2.vertical(5).bindData(
            housetypeData2,
            R.layout.item_popwidow_findhouse_sel_house_type
        ) { holder, item, position ->
            val view = holder.getView<TextView>(R.id.name)
            view.text = item.name
            if (item.isSelect) {
                view.setBackgroundResource(R.drawable.item_popwindow_findhouse_sel_house_type_sel)
                view.setTextColor(color(R.color.white))
            } else {
                view.setBackgroundResource(R.drawable.item_popwindow_findhouse_sel_house_type)
                view.setTextColor(color(R.color.gray_99))
            }
        }.itemClick { data: List<Sel>, holder, position ->
            for (s in housetypeData1) {
                s.isSelect = false
            }
            for (s in housetypeData2) {
                s.isSelect = false
            }
            mHouseTypeSel = data[position]
            data[position].isSelect = true
            rv2.updateData(data)
            rv1.updateData(housetypeData1)
        }
        mHouseTypePop = object : BasePopupWindow(this) {
            override fun onCreateShowAnimation(): Animation {
                return AnimationHelper.asAnimation()
                    .withTranslation(TranslationConfig.FROM_TOP)
                    .toShow()
            }

            override fun onCreateDismissAnimation(): Animation {
                return AnimationHelper.asAnimation()
                    .withTranslation(TranslationConfig.TO_TOP)
                    .toDismiss()
            }
        }.apply {
            contentView = viewGroup
            setPopupGravity(Gravity.BOTTOM)
            setHeight(ViewGroup.LayoutParams.WRAP_CONTENT)
            setWidth(ViewGroup.LayoutParams.MATCH_PARENT)
            setAlignBackground(true)
        }
        mHouseTypePop.setOnDismissListener(object : BasePopupWindow.OnDismissListener() {
            override fun onDismiss() {
                if (!mHouseTypeSel.name.isNullOrEmpty()) {
                    mView.sel2.setDrawRight(R.mipmap.up_triangle_sel_down)
                    mView.sel2.setColor(R.color.color_1273f7)
                } else {
                    mView.sel2.setDrawRight(R.mipmap.up_triangle_down)
                    mView.sel2.setColor(R.color.black_66)
                }
                getData()
                mView.statusView.showLoading()
            }

        })

        mView.sel2.setOnClickListener {
            mView.sel2.setDrawRight(R.mipmap.up_triangle_sel)
            mView.sel2.setColor(R.color.color_1273f7)
            dismissPop()
            if (mShareViewModel.apartmentType.value == "1") {
                tv_empty1.gone()
                rv2.gone()
            } else {
                tv_empty1.visible()
                rv2.visible()
            }
            mHouseTypePop.showPopupWindow(it)
        }
    }

    fun initPricePopwindow() {
        mPriceSel = Sel()
        var viewGroup = layoutInflater.inflate(R.layout.popwindow_find_house_sel3, null)
        var priceData = mutableListOf<Sel>()
        priceData.add(Sel(mPrice[0], null, true))
        priceData.add(Sel(mPrice[1], null, false, 0, 500))
        priceData.add(Sel(mPrice[2], null, false, 500, 1000))
        priceData.add(Sel(mPrice[3], null, false, 1000, 2000))
        priceData.add(Sel(mPrice[4], null, false, 2000, 3000))
        priceData.add(Sel(mPrice[5], null, false, 3000, 0))
        var rv1 = viewGroup.findViewById<RecyclerView>(R.id.rv1)
        var min = viewGroup.findViewById<EditText>(R.id.min)
        var max = viewGroup.findViewById<EditText>(R.id.max)
        min.addTextChangedListener(object : MyTextWatcher() {
            override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
            }

            override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
            }

            override fun afterTextChanged(s: Editable?) {
                for (st in priceData) {
                    st.isSelect = false
                }
                mPriceSel = Sel()
                rv1.updateData(priceData)
            }
        })
        max.addTextChangedListener(object : MyTextWatcher() {
            override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
            }

            override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
            }

            override fun afterTextChanged(s: Editable?) {
                for (s in priceData) {
                    s.isSelect = false
                }
                mPriceSel = Sel()
                rv1.updateData(priceData)
            }
        })
        viewGroup.findViewById<View>(R.id.reset).setOnClickListener {
            min.setText("")
            max.setText("")
            var sel = priceData[0]
            sel.isSelect = true
            mPriceSel = sel
            rv1.updateData(priceData)
        }
//        viewGroup.findViewById<View>(R.id.cancel).setOnClickListener {
//            mPricePop.dismiss()
//        }
        viewGroup.findViewById<View>(R.id.ok).setOnClickListener {
            mPricePop.dismiss()
        }
        rv1.vertical().bindData(
            priceData,
            R.layout.item_popwidow_findhouse_sel_price
        ) { holder, item, position ->
            val view = holder.getView<TextView>(R.id.name)
            view.text = item.name
            if (item.isSelect) {
                view.setColor(R.color.color_1273f7)
            } else {
                view.setColor(R.color.gray_99)
            }
        }.itemClick { data: List<Sel>, holder, position ->
            for (s in priceData) {
                s.isSelect = false
            }
            mPriceSel = data[position]
            data[position].isSelect = true
            rv1.updateData(data)
        }
        mPricePop = object : BasePopupWindow(this) {
            override fun onCreateShowAnimation(): Animation {
                return AnimationHelper.asAnimation()
                    .withTranslation(TranslationConfig.FROM_TOP)
                    .toShow()
            }

            override fun onCreateDismissAnimation(): Animation {
                return AnimationHelper.asAnimation()
                    .withTranslation(TranslationConfig.TO_TOP)
                    .toDismiss()
            }
        }.apply {
            contentView = viewGroup
            setPopupGravity(Gravity.BOTTOM)
            setHeight(ViewGroup.LayoutParams.WRAP_CONTENT)
            setWidth(ViewGroup.LayoutParams.MATCH_PARENT)
            setAlignBackground(true)
        }
        mPricePop.setOnDismissListener(object : BasePopupWindow.OnDismissListener() {
            override fun onDismiss() {
                if (!mPriceSel.name.isNullOrEmpty() && mPriceSel.name != "不限") {
                    mView.sel3.setDrawRight(R.mipmap.up_triangle_sel_down)
                    mView.sel3.setColor(R.color.color_1273f7)
                } else if (!min.getTextZ().isNullOrEmpty() || !max.getTextZ().isNullOrEmpty()) {
                    mView.sel3.setDrawRight(R.mipmap.up_triangle_sel_down)
                    mView.sel3.setColor(R.color.color_1273f7)
                    mPriceSel = Sel(
                        "", null, false,
                        if (!min.getTextZ().isNullOrEmpty()) min.getTextZ().toInt() else 0,
                        if (!max.getTextZ().isNullOrEmpty()) max.getTextZ().toInt() else 0
                    )
                } else {
                    mView.sel3.setDrawRight(R.mipmap.up_triangle_down)
                    mView.sel3.setColor(R.color.black_66)
                }
                getData()
                mView.statusView.showLoading()
            }

        })
        mView.sel3.setOnClickListener {
            mView.sel3.setDrawRight(R.mipmap.up_triangle_sel)
            mView.sel3.setColor(R.color.color_1273f7)
            dismissPop()
            mPricePop.showPopupWindow(it)
        }
    }

    open inner class MyTextWatcher : TextWatcher {
        override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
        }

        override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
        }

        override fun afterTextChanged(s: Editable?) {
        }
    }

    fun initHdirectionPopwindow(directionData: MutableList<Sel> = mdirectionData) {
        for (s in directionData) {
            s.isSelect = false
        }
        mDirectionSel = Sel()
        val viewGroup = layoutInflater.inflate(R.layout.popwindow_find_house_sel4, null)
        var rv1 = viewGroup.findViewById<RecyclerView>(R.id.rv1)
        viewGroup.findViewById<View>(R.id.reset).setOnClickListener {
            for (s in directionData) {
                s.isSelect = false
            }
            mDirectionSel = Sel()
            rv1.updateData(directionData)
        }
//        viewGroup.findViewById<View>(R.id.cancel).setOnClickListener {
//            mDirectionPop.dismiss()
//        }
        viewGroup.findViewById<View>(R.id.ok).setOnClickListener {
            mDirectionPop.dismiss()
        }
        rv1.vertical(4).bindData(
            directionData,
            R.layout.item_popwidow_findhouse_sel_house_type
        ) { holder, item, position ->
            val view = holder.getView<TextView>(R.id.name)
            view.text = item.name
            if (item.isSelect) {
                view.setBackgroundResource(R.drawable.item_popwindow_findhouse_sel_house_type_sel)
                view.setTextColor(color(R.color.white))
            } else {
                view.setBackgroundResource(R.drawable.item_popwindow_findhouse_sel_house_type)
                view.setTextColor(color(R.color.gray_99))
            }
        }.itemClick { data: List<Sel>, holder, position ->
            for (s in directionData) {
                s.isSelect = false
            }
            mDirectionSel = data[position]
            data[position].isSelect = true
            rv1.updateData(data)
        }
        mDirectionPop = object : BasePopupWindow(this) {
            override fun onCreateShowAnimation(): Animation {
                return AnimationHelper.asAnimation()
                    .withTranslation(TranslationConfig.FROM_TOP)
                    .toShow()
            }

            override fun onCreateDismissAnimation(): Animation {
                return AnimationHelper.asAnimation()
                    .withTranslation(TranslationConfig.TO_TOP)
                    .toDismiss()
            }
        }.apply {
            contentView = viewGroup
            setPopupGravity(Gravity.BOTTOM)
            setAlignBackground(true)
            setHeight(ViewGroup.LayoutParams.WRAP_CONTENT)
            setWidth(ViewGroup.LayoutParams.MATCH_PARENT)
        }
        mDirectionPop.setOnDismissListener(object : BasePopupWindow.OnDismissListener() {
            override fun onDismiss() {
                if (!mDirectionSel.name.isNullOrEmpty()) {
                    mView.sel4.setDrawRight(R.mipmap.up_triangle_sel_down)
                    mView.sel4.setColor(R.color.color_1273f7)
                } else {
                    mView.sel4.setDrawRight(R.mipmap.up_triangle_down)
                    mView.sel4.setColor(R.color.black_66)
                }
                getData()
                mView.statusView.showLoading()
            }

        })
        mView.sel4.setOnClickListener {
            mView.sel4.setDrawRight(R.mipmap.up_triangle_sel)
            mView.sel4.setColor(R.color.color_1273f7)
            dismissPop()
            mDirectionPop.showPopupWindow(it)
        }
    }

    data class Sel(
        var name: String = "",
        var list: MutableList<Sel>? = null,
        var isSelect: Boolean = false,
        var minPrice: Int = 0,
        var maxPrice: Int = 0,
        var houseType: String = "",
        var id: String = ""
    )

    inner class VListAdpater(
        list: MutableList<FindHouse>
    ) : BaseQuickAdapter<FindHouse, BaseViewHolder>(
        R.layout.item_find_house,
        list
    ) {
        override fun convert(holder: BaseViewHolder, item: FindHouse) {
            holder.loadImage(R.id.photo, item.picUrl, R.mipmap.error_empty_zheng, 5f)
            holder.setText(R.id.title_name, item.houseName)
            holder.setText(
                R.id.desc,
                "${item.doorName}\u0020\u0020${item.area}㎡\u0020\u0020${item.orientation}"
            )
            holder.setText(R.id.address, item.address)
            var flow = holder.getView<FlowTagLayout>(R.id.flow)
            flow.setAdapter(object : DefaultFlowTagAdapter(this@ZKFindHouseActivity) {
                override fun getLayoutId(): Int {
                    return R.layout.item_find_house_list_flow
                }
            })
            flow.setItems(item.featureList)
            var money = holder.getView<TextView>(R.id.money)
            if (mShareViewModel.apartmentType.value!! == "1") {//人才公寓
                money.text = ""
                money.appendStyleSpan("面议")
            } else {
                money.text = "￥${item.rentPrice}"
                money.appendSizeSpan("/月", 0.46f)
                    .colorSpan(
                        "",
                        money.text.length - 2..money.text.length,
                        color(R.color.black_66)
                    )
                    .styleSpan("", 0..money.text.length - 2)
            }
        }
    }

    fun dismissPop() {
        if (mLocationPop != null && mLocationPop.isShowing)
            mLocationPop.dismiss()
        if (mHouseTypePop != null && mHouseTypePop.isShowing)
            mHouseTypePop.dismiss()
        if (mPricePop != null && mPricePop.isShowing)
            mPricePop.dismiss()
        if (mDirectionPop != null && mDirectionPop.isShowing)
            mDirectionPop.dismiss()
    }

    inner class SelAdpater(
        list: MutableList<Sel>
    ) : BaseQuickAdapter<Sel, BaseViewHolder>(
        R.layout.item_find_house_sel,
        list
    ) {
        override fun convert(holder: BaseViewHolder, item: Sel) {
            val name = holder.getView<TextView>(R.id.name)
            val line = holder.getView<View>(R.id.line)
            if (item.isSelect) {
                name.setTextColor(color(R.color.color_1273f7))
                line.visibility = View.VISIBLE
            } else {
                name.setTextColor(color(R.color.black_66))
                line.visibility = View.INVISIBLE
            }
            name.text = item.name
        }
    }
}